package org.opens.util;

import org.apache.cxf.endpoint.Client;
import org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory;

/**
 * 功能描述
 *
 * @author by zhangyuming
 * @date 2022/8/18
 */
public class ClientUtil {

    /**
     * 调用webservice服务端接口的工具类方法
     * @param wsdUrl webservice接口地址
     * @param operationName webservice函数名称
     * @param params 参数
     */
    public static String callWebSV(String wsdUrl, String operationName, String... params) throws Exception {
        JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance();
        Client client = dcf.createClient(wsdUrl);
        //client.getOutInterceptors().add(new ClientLoginInterceptor(USER_NAME, PASS_WORD));
        Object[] objects;
        // invoke("方法名",参数1,参数2,参数3....);
        objects = client.invoke(operationName, params);
        return objects[0].toString();
    }

    public static void main(String[] args) throws Exception {
        String url = "http://localhost:30002/webService/CatService?wsdl";
        String methodName = "message";

        System.out.println(ClientUtil.callWebSV(url, methodName, "ssss"));
    }

}
